package org.subatu.orm.query.condition;


import org.subatu.orm.query.base.BaseSql;
import org.subatu.orm.util.ChkUtil;

/**
 * 查询
 */
public interface Having extends BaseSql {

    // StringBuilder havingSql = new StringBuilder();


    default OrderBy havingSql(String sql) {
        sqlData().havingSql.append(sql);
        return (OrderBy) this;
    }


    default String buildHavingSql() {
        if (sqlData().havingSql.length() > 0 || ChkUtil.isNull(sqlData().havingList)) {
            // 如果手工设置了 sql, 直接返回
            return sqlData().havingSql.toString();
        }

        sqlData().havingSql.setLength(0);
        sqlData().havingSql.append(" having ");

        String allCondSql = getAllCondSql(sqlData().havingList);
        sqlData().havingSql.append(allCondSql);

        return sqlData().havingSql.toString();
    }
}
